import requests
import base64
url = 'https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic'  

data = {}  
data['access_token']='24.99251c898e73d20654644d70dd558cf1.2592000.1525103276.282335-11028562'


#读取图片  
file=open('jietu.jpg','rb')  
image= file.read()  
file.close()  

data['image'] = base64.b64encode(image)  
headers={
    "Content-Type":"application/x-www-form-urlencoded",
    "apikey":"bN7UbbadGNuM00S5v1B0cP6H"
}

res = requests.post(url=url,headers=headers,data=data)
result = res.json()
print(result)

# with open("1.txt","a") as f:
#     for line in result["words_result"]:
#         print(line["words"],end="")
#         f.write(line["words"]+"\n")